let http = require('http'),
fs = require('fs'),
zlib = require('zlib');

let gzip = zlib.createGzip()

let options = {
  hostname: 'localhost',
  port: 3000,
  method: 'POST',
  headers: {
    'Content-Type': 'application/javascript',
    'Content-Encoding': 'gzip,deflate'
  }
}


let req = http.request(options, (res) => {  
  console.log('STATUS:'+ res.statusCode)
  console.log('HEADERS:' + JSON.stringify(res.headers))
  res.setEncoding('utf8')
  let  data = ''
  res.on('data', (chunk) => {
    data+= chunk
  })

  // end response
  res.on('end' , () => {
    console.log('end:', data)
  })
})

req.on('error', (e) => {
  console.log('Problem with request: ' + e.message)
})

// stream gzipped file to server
let readable = fs.createReadStream('./_SAM8018.JPG')
readable.pipe(gzip).pipe(req)


console.log('Server running....')